package com.example.bittraffic;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Toast;

public class Activity_Bus extends Activity implements OnClickListener {

	ImageView iv1, iv2, iv3;
	View v1, v2, v3;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_bus);

		iv1 = (ImageView) findViewById(R.id.btn1);
		iv2 = (ImageView) findViewById(R.id.btn2);
		// iv3 = (ImageView) findViewById(R.id.btn3);
		iv1.setOnClickListener(this);
		iv2.setOnClickListener(this);
		// iv3.setOnClickListener(this);
		v1 = (View) findViewById(R.id.xml1);
		v2 = (View) findViewById(R.id.xml2);
		// v3 = (View) findViewById(R.id.xml3);

		initView1();
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn1:
			initView1();
			break;
		case R.id.btn2:
			initView2();
			break;
		// case R.id.btn3:
		// initView3();
		// break;
		}
	}

	// private void initView3() {
	// v1.setVisibility(View.GONE);
	// v2.setVisibility(View.GONE);
	// v3.setVisibility(View.VISIBLE);
	// iv1.setImageResource(R.drawable.image_message2);
	// iv2.setImageResource(R.drawable.image_message2);
	// iv3.setImageResource(R.drawable.image_message);
	// }

	private void initView2() {
		v1.setVisibility(View.GONE);
		v2.setVisibility(View.VISIBLE);
		// v3.setVisibility(View.GONE);
		iv1.setImageResource(R.drawable.image_message2);
		iv2.setImageResource(R.drawable.image_message);
		// iv3.setImageResource(R.drawable.image_message2);
	}

	private void initView1() {
		v1.setVisibility(View.VISIBLE);
		v2.setVisibility(View.GONE);
		// v3.setVisibility(View.GONE);
		iv1.setImageResource(R.drawable.image_message);
		iv2.setImageResource(R.drawable.image_message2);
		// iv3.setImageResource(R.drawable.image_message2);
	}

	// public boolean onKeyDown(int keyCode, KeyEvent event) {
	// switch (keyCode) {
	// case KeyEvent.KEYCODE_BACK: {
	// Intent intent = new Intent(getApplicationContext(),
	// Activity_Main2.class);
	// startActivity(intent);
	// }
	// }
	// return false;
	// }

	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.setQwertyMode(true);

		// SubMenu sm = menu.addSubMenu(0, 0, 0, "버스");
		// sm.add(1, 0, 0, "버스0");
		// sm.add(1, 1, 1, "버스1");

		// MenuItem mi = menu.add(0, 0, 0, "버스");
		// mi.setAlphabeticShortcut('a');

		menu.add(0, 2, 2, "유스퀘어").setAlphabeticShortcut('a')
				.setIcon(R.drawable.image_bus);

		menu.add(0, 0, 0, "지하철").setAlphabeticShortcut('b')
				.setIcon(R.drawable.image_subway);

		menu.add(0, 1, 1, "택시").setAlphabeticShortcut('c')
				.setIcon(R.drawable.image_taxi);

		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == 2) {
			// Intent intent = new Intent(Intent.ACTION_VIEW);
			// intent.setData(Uri.parse("http://m.usquare.co.kr"));
			// startActivity(intent);
			// finish();
			Intent intent = new Intent(getApplicationContext(),
					Activity_Bus_Usquare.class);
			startActivity(intent);
			finish();

		}
		if (item.getItemId() == 0) {
			Intent intent = new Intent(getApplicationContext(),
					Activity_Subway.class);
			// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			finish();
		}
		if (item.getItemId() == 1) {
			Intent intent = new Intent(getApplicationContext(),
					Activity_Taxi.class);
			// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			finish();
		}
		return false;
	}
}
